package com.haiwee.springbootjdbctemplate.controll;

import com.haiwee.springbootjdbctemplate.pojo.User;
import com.haiwee.springbootjdbctemplate.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Auther: lichufeng
 * @Date: 2018/12/17 14:34
 * @Description:
 */
@RestController
@RequestMapping("/user")
public class SpringJdbcController {

	@Autowired
	private UserService userService;

	@GetMapping()
	public List<User> queryUsers(){

		return userService.queryUsers();
	}

	@GetMapping("/{id}")
	public User getUser(@PathVariable Long id){
		return userService.getUser(id);
	}

	@DeleteMapping("/{id}")
	public int delUser(@PathVariable Long id){
		return userService.delUser(id);
	}

	@PostMapping
	public int addUser(@RequestBody User user){

		return userService.addUser(user);
	}

	@PutMapping("/{id}")
	public int editUser(@PathVariable Long id,@RequestBody User user){
		return userService.editUser(user,id);
	}
}
